$(function(){
	$("#beginTime").datepicker();
	$("#endTime").datepicker();
	ajax_table();
});
//结算模式改变
function on_method_onchange(){
	$("#utable").bootstrapTable('destroy');
	ajax_table();
}
function ajax_table(type){
	  //生成用户数据
	   var url = path+"/admin/get-two-channel-list.htm";
		var condition_id=$("#condition_id").val();
		if(!condition_id){
			condition_id=0
		}
		if(condition_id<0){
			alert("渠道ID格式不正确");
		}
	    $('#utable').bootstrapTable({
	        url: url,
	        method: 'post',
	        contentType: "application/x-www-form-urlencoded",
	        queryParamsType:'', 
	        queryParams: function (params){
	        	return {
	        		pageSize: params.limit,
	        		page:params.pageNumber,
	        		condition_id:condition_id,
	        		condition_name:$("#condition_name").val(),
	        		t_settlement_method:$("#t_settlement_method").val()
	        	}
	        }, 
	        //【其它设置】
	        locale:'zh-CN',//中文支持
	        pagination: true,//是否开启分页（*）
	        pageNumber:1,//初始化加载第一页，默认第一页
	        pageSize: 10,//每页的记录行数（*）
	        sidePagination: "server", //分页方式：client客户端分页，server服务端分页（*）
	        //【设置列】
	        columns: [
	                  {
	              		title:'二级渠道ID',
	              		field:'t_uid',
	              		align:'center',
	              		formatter:function(value,row){
	              			return value+10000;
	              		}
	              	},
	              	{
	              		title:'二级渠道名称',
	              		align:'center',
	              		field:'t_real_name'
	              	},
	              	{
	              		title:'上级渠道ID',
	              		align:'center',
	              		field:'parentId',
	              		formatter:function(value){
	              			return value+10000;
	              		}
	              	},
	             	{
	              		title:'上级渠道名称',
	              		align:'center',
	              		field:'parent_anme'
	              	},
	            	{
	              		title:'充值收益',
	              		align:'center',
	              		field:'gold_income'
	              	},
	             	{
	              		title:'VIP收益',
	              		align:'center',
	              		field:'vip_income' 
	              	},
	            	{
	              		title:'总收益',
	              		align:'center',
	              		formatter:function(value,row,index){
	              			return row.gold_income+row.vip_income;
	              		}
	              	},
	            	{
	              		title:'已结算',
	              		align:'center',
	              		field:'settlement' 
	              	},
	               	{
	              		title:'未结算',
	              		align:'center',
	              		formatter:function(value,row,index){
	              			return (row.gold_income+row.vip_income)-row.settlement;
	              		}
	              	}
	        ]
	    });
}

/**
 * 点击弹窗
 * @param id
 * @param nickName
 */
function on_click_open_update_model(obj){
	$.ajax({
		type : 'POST',
		url : path + '/admin/get-channel-detail.htm',
		data : {t_id : obj.t_id},
		dataType : 'json',
		success : function(data) {
			$('#t_id').val(data.t_id);
			$('#t_real_name').val(data.t_real_name);
			$('#t_gold_commission').val(data.t_gold_commission);
			$('#t_vip_commission').val(data.t_vip_commission);
			$('#t_settlement_type').val(data.t_settlement_type);
			$('#t_bank_number').val(data.t_bank_number);
			if(data.t_settlement_type == 2){
				$('#t_bank_of_deposit').val(data.t_bank_of_deposit);
				$('#t_account_name').val(data.t_account_name);
			} else if(data.t_settlement_type == 0){
				$('#t_account_name').val(data.t_account_name);
				$('#div_account_name').show();
			}
		}
	});
	$("#myModal").modal('show');
}

function on_change_select(){
	var value  = $('#t_settlement_type').val();
	
	if(value === '2'){
		$('#div_bank_of_deposit').show();
		$('#div_account_name').show();
	} else if(value === '1'){
		$('#div_bank_of_deposit').hide();
		$('#div_account_name').hide();
	} else {
		$('#div_account_name').show();
		$('#div_bank_of_deposit').hide();
	}
}
/**
 * 点击提交新增或修改
 */
function on_click_submit(){
	$.ajax({
		type : 'POST',
		url : path + '/admin/update-channel.htm',
		data : {
			t_id:$('#t_id').val(),
			t_real_name:$('#t_real_name').val(),
			t_gold_commission:$('#t_gold_commission').val(),
			t_vip_commission:$('#t_vip_commission').val(),
			t_settlement_type:$('#t_settlement_type').val(),
			t_bank_number:$('#t_bank_number').val(),
			t_account_name:$('#t_account_name').val(),
			t_bank_of_deposit:$('#t_bank_of_deposit').val()
		},
		dataType : 'json',
		success : function(data) {
			if (data.m_istatus == 1) {
				$("#myModal").modal('hide');
				$("#utable").bootstrapTable('refreshOptions',{page : 1});
			} else  {
				window.location.href = path + '/error.html';
			}
		}
	});
}

//启用或者停用
function on_click_del(id,t_start_using){
	$.ajax({
		type : 'POST',
		url : path + '/admin/start-or-stop-channel.htm',
		data : {
			t_id : id,
			start_using:t_start_using
		},
		dataType : 'json',
		success : function(data) {
			if (data.m_istatus == 1) {
				$("#myModal").modal('hide');
				$("#utable").bootstrapTable('refreshOptions',{page : 1});
			} else  {
				window.location.href = path + '/error.html';
			}
		}
	});
}


 
 


